<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .animate{
            transition: width 3s;
            width: 100px;
            height: 100px;
            background-color: red;
        }
    </style>
</head>
<body>
    <button onclick="changeWidth()">变宽</button>
    <div class="animate" id="demo">

    </div>
</body>
<script>
    function changeWidth(){
        document.getElementById("demo").style.width = "300px";
    }
</script>
</html>